package com.joysuch.wwyt.bp.entity.vo;

import com.joysuch.wwyt.bp.entity.dto.CheckRecordDto;
import com.joysuch.wwyt.common.bean.KLMapping;
import com.joysuch.wwyt.core.bean.SimpleSelectListBean;
import com.joysuch.wwyt.risk.entity.vo.RiskMeasureTypeNode;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
@Data
public class CheckRecordVo extends CheckRecordDto implements Comparable<CheckRecordVo> {
    // 排查人员（只给id、name）
    List<SimpleSelectListBean> executors;
    // 管控措施类型树
    private RiskMeasureTypeNode riskMeasureTypeNode;
    // 排查完成人
    private KLMapping finisher;
    // 是否已放入时间片
    private boolean hasUsed;
    // 结论(快照页面)
    private String checkVerdict;
    // 快照颜色显示
    private String viewColor;

    /**
     * 比较规则：先比较周期单位（周期单位非空）：null > 年 > 月 > 天 > 时
     *         再比较周期值：具体数值直接比大小，null > 具体数值
     * @param o
     * @return
     */
    @Override
    public int compareTo(CheckRecordVo o) {
        if (StringUtils.isNotBlank(this.getPeriodUnit()) && StringUtils.isNotBlank(o.getPeriodUnit())) {
            int unitWeightDif = getUnitWeights(this.getPeriodUnit()) - getUnitWeights(o.getPeriodUnit());
            // 比较周期单位
            if (unitWeightDif > 0) {
                return 1;
            }else if (unitWeightDif < 0) {
                return -1;
            }else {
                // 周期单位相同时，比较周期数值
                if (this.getPeriodDays() != null && o.getPeriodDays() != null) {
                    return this.getPeriodDays() - o.getPeriodDays();
                }else if (this.getPeriodDays() != null && o.getPeriodDays() == null) {
                    return -1;
                }else if (this.getPeriodDays() == null && o.getPeriodDays() != null) {
                    return 1;
                }else {
                    return 0;
                }
            }
        }
        return 0;
    }

    private static int getUnitWeights(String unit) {
        int weights = 0;
        if (StringUtils.isNotBlank(unit)) {
            if (StringUtils.isNotBlank(unit)) {
                switch (unit){
                    case "时":
                        weights = 1;
                        break;
                    case "日":
                        weights = 2;
                        break;
                    case "周":
                        weights = 3;
                        break;
                    case "月":
                        weights = 4;
                        break;
                    case "年":
                        weights = 5;
                }
            }
        }else {
            weights = 6;
        }
        return weights;
    }

}
